package com.gs.cd.service.tenant.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diboot.core.binding.Binder;
import com.gs.cd.service.auth.model.AuthUser;
import com.gs.cd.service.tenant.model.SysTenantOwnUser;
import com.gs.cd.service.tenant.mapper.SysTenantOwnUserMapper;
import com.gs.cd.service.tenant.service.SysTenantOwnUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author seven
 * @since 2020-12-22
 */
@Service
public class SysTenantOwnUserServiceImpl extends ServiceImpl<SysTenantOwnUserMapper, SysTenantOwnUser> implements SysTenantOwnUserService {

    @Override
    public List<AuthUser> listOwnUser(String tenantCode) {
        LambdaQueryWrapper<SysTenantOwnUser> eq = new QueryWrapper<SysTenantOwnUser>().lambda()
                .eq(SysTenantOwnUser::getTenantCode, tenantCode);
        List<SysTenantOwnUser> list = list(eq);
        List<SysTenantOwnUser> sysTenantOwnUsers = Binder.convertAndBindRelations(list, SysTenantOwnUser.class);
        return sysTenantOwnUsers.stream().map(SysTenantOwnUser::getAuthUser).collect(Collectors.toList());
    }
}
